import { NestFactory } from '@nestjs/core';
import { VersioningType } from '@nestjs/common';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  // 版本控制
  const defaultVersion = '1.0';
  app.enableVersioning({
    type: VersioningType.URI,
    defaultVersion,
  });

  // 允许跨域
  app.enableCors();

  // 构建swagger文档
  const options = new DocumentBuilder()
    .setTitle('api')
    .setDescription('个人api文档')
    .setVersion('1.0')
    .addBearerAuth()
    .build();
  const document = SwaggerModule.createDocument(app, options);
  SwaggerModule.setup('docs', app, document);

  const prot = 9090;
  // 服务端口
  await app.listen(prot);
  console.log(`服务运行地址 http://localhost:${prot}/v${defaultVersion}/`);
  console.log(`Swagger文档地址 http://localhost:${prot}/docs`);
}
bootstrap();
